let has = [];
let queue = [];
let pending = false;
import {nextTick} from '../nextTick'
export function queueWatcher(watcher){
    // 合并watcher, 统一渲染
    /*
    vm.count = 1;
    vm.count2 = 2;
    vm.count3 = 3;
    只会触发一次渲染
    */
    const id = watcher.id;
    // 同一个watcher只进入一次。
    if (has[id]){
        return;
    }
    queue.push(watcher);
    has[id] = true;
    if (!pending){
        nextTick(flushSchedularQueue);
    }
}
function flushSchedularQueue(){
    // 拷贝一份
    const cbs = queue.slice();
    queue = [];
    has = [];
    pending = false;

    for (let i=0; i<cbs.length; i++){
        cbs[i].run();
    }
}